package com.dhecp.project.finance.controller;

import com.dhecp.common.annotation.Log;
import com.dhecp.common.annotation.RepeatSubmit;
import com.dhecp.common.core.domain.AjaxResult;
import com.dhecp.common.core.page.TableDataInfo;
import com.dhecp.common.enums.BusinessType;
import com.dhecp.common.utils.TypeUtils;
import com.dhecp.core.constant.ModuleTable;
import com.dhecp.core.layui.GridColumnsPropertyModel;
import com.dhecp.core.utils.ExportExcelUtils;
import com.dhecp.project.common.controller.BaseModuleController;
import com.dhecp.project.finance.domain.TcwCapitalRegisterClaim;
import com.dhecp.project.finance.service.TcwCapitalRegisterClaimService;
import com.dhecp.project.system.domain.SysDictionaryForExport;
import com.dhecp.project.system.service.SysDictionaryForFieldService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.*;

/**
 * 资金登记认领表(TCW_CapitalRegisterClaim)控制层
 *
 */
@Controller
@RequestMapping("/finance/tcwCapitalRegisterClaim")
public class TcwCapitalRegisterClaimController extends BaseModuleController{

    private String prefix = "finance/tcwCapitalRegisterClaim";
    private String moduleTable = ModuleTable.TCW_CAPITALREGISTERCLAIM;

    @Autowired
    private SysDictionaryForFieldService dictionaryForFieldService;

    @Autowired
    private TcwCapitalRegisterClaimService tcwCapitalRegisterClaimService;

    @Autowired
    private GridColumnsPropertyModel gridColumnsPropertyModel;


    /**
     * @Description: 打开查询列表页
     * @Param: [params]
     * @return: org.springframework.web.servlet.ModelAndView
     * @Author: hlf
     * @date: 2022-08-15 15:42
     */
    @RequiresPermissions("finance:tcwCapitalRegisterClaim:view")
    @GetMapping()
    public ModelAndView view(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        params.put("entity", new TcwCapitalRegisterClaim()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("prefix", prefix + "/tcwCapitalRegisterClaim"); //页面路径
        params.put("toolBarWidth", 0);
        params.put("checkBox", "yes");

        ModelAndView mv = this.openListPage(params);
        mv.addObject("finance", "tcwCapitalRegisterClaim");
        return mv;
    }

    /**
     * @Description: 查询页 列表数据
     * @Param: [params]
     * @return: com.dhecp.common.core.page.TableDataInfo
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("finance:tcwCapitalRegisterClaim:list")
    @GetMapping("/list")
    @ResponseBody
    public TableDataInfo list(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<TcwCapitalRegisterClaim> list = new ArrayList<>();
        try {
            list = tcwCapitalRegisterClaimService.queryList(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

    /**
     * @Description: 数据导出Excel
     * @Param: [params]
     * @return: com.dhecp.common.core.domain.AjaxResult
     * @Author: hlf
     * @date: 2022-08-15 15:43
     */
    @RequiresPermissions("finance:tcwCapitalRegisterClaim:export")
    @Log(title = "资金登记认领表导出", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    @ResponseBody
    @RepeatSubmit
    public AjaxResult export(@RequestParam Map<String, Object> params) throws Exception {
        params.put("moduleTable", moduleTable);
        params.put("entity", new TcwCapitalRegisterClaim());

        List<TcwCapitalRegisterClaim> list = tcwCapitalRegisterClaimService.queryList(params);

        params.put("getFieldAttributesType", "export");
        List<SysDictionaryForExport> fieldList = dictionaryForFieldService.queryExportFieldList(params);
        ExportExcelUtils<TcwCapitalRegisterClaim> util = new ExportExcelUtils<>(moduleTable, new TcwCapitalRegisterClaim());
        return util.exportExcel(list, fieldList, "资金登记认领表", "export");
    }




    /**
     * 选择资金登记认领表
     *
     * @param params
     * @return ModelAndView
     * @author DH-Xxj
     */
    @GetMapping("/select2")
    public ModelAndView selectbusinessList(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        params.put("entity", new TcwCapitalRegisterClaim()); //生成表格gridColumns对应的实体，用于获取实体属性生成表格字段
        params.put("toolBarWidth", 0);
        if (params.get("pagetype") != null && params.get("pagetype").toString().equalsIgnoreCase("checkbox"))
            params.put("checkBox", "yes");
        else params.put("radio", "yes");
        ModelAndView mv = this.getModelAndView();
        AjaxResult ajaxResult = new AjaxResult();
        Map<String, Object> dictionaryForFieldMap = new HashMap<String, Object>();
        mv.addObject("fields", TypeUtils.mapToJson(dictionaryForFieldMap));
        mv.addObject("ajaxResult", ajaxResult);
        mv.addObject("gridColumns", gridColumnsPropertyModel.queryGridColumnsPropertyModel(params));
        mv.addObject("prefix", prefix);
        mv.addObject("moduleTable", moduleTable);
        mv.addObject("pagetype", params.get("pagetype").toString());
        mv.addObject("fmoduleTable", params.get("fmoduleTable").toString());
        //查询条件
        System.out.println("params"+params);
        mv.addObject("paymentTime", params.get("paymentTime").toString());
        mv.addObject("paymentBankName", params.get("paymentBankName").toString());
        mv.addObject("paymentBank", params.get("paymentBank").toString());
        mv.addObject("paymentBankAccount", params.get("paymentBankAccount").toString());
        mv.addObject("paymentAmount", params.get("paymentAmount").toString());

        mv.setViewName("system/organization/mzjobject_select");
        return mv;
    }



    /**
     * 认领表单弹出框的资金登记认领表信息查询
     */
    @GetMapping("/findInfoListByCapitalSelectModel")
    @ResponseBody
    public TableDataInfo findInfoListByCapitalSelectModel(@RequestParam Map<String, Object> params) {
        params.put("moduleTable", moduleTable);
        List<TcwCapitalRegisterClaim> list = new ArrayList<>();
        try {
            String paymentTime = params.get("paymentTime").toString();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            Date date = dateFormat.parse(paymentTime);
            params.put("paymentTime",date);
            list = tcwCapitalRegisterClaimService.findInfoListByCapitalSelectModel(params);
        } catch (Exception e) {
            e.printStackTrace();
            return getDataTable(this.getExceptionMessage(e).toString());
        }
        return getDataTable(list);
    }

}

